<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.js"></script>
    <script type="text/javascript" src="../js/respond.min.js"></script>
    <![endif]-->
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="../css/H-ui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../css/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <title></title>
</head>
<body>
<article class="page-container saveProductChannelFee">
    <form action="" method="post" class="form form-horizontal" id="tradeForm">
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>客户姓名：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="name" name="name"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>证件号码：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="certCode" name="certCode"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>手机号：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="mobile" name="mobile"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>微信OpenId：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="openId" name="openId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>微信unionId：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="unionId" name="unionId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>微信昵称：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="nickname" name="nickname"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>微信头像URL：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <div class="imageShow imageAppend hide">
                        <ul class="clearfix fileCon">
                        </ul>
                    </div>
                    <!--<div class="fileLoad pos_r addFileLoad">-->
                        <!--<div class="btn btn-primary radius" onclick="fileClick()">选择图片</div>-->
                        <!--<input type="file" class="pos_a hide" onchange="changeFile(this)">-->
                    <!--</div>-->
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>直接推荐人：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="bbId" name="bbId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>间接推荐人：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="yyId" name="yyId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>起点推荐人：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="zzId" name="zzId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>配送商：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="distributionCenterId" name="distributionCenterId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>客户种类：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="vipType" id="vipType" disabled>
                        <option value="">-请选择-</option>
                        <option value="0">游客</option>
                        <option value="10">VIP</option>
                        <option value="20">配送商</option>
                    </select>
                </div>
            </div>

        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>会员等级：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="vipRank" id="vipRank">
                        <option value="">-请选择-</option>
                        <option value="10">乡镇</option>
                        <option value="20">市区</option>
                        <option value="30">省</option>
                    </select>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>微信性别：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="sex" id="sex" disabled>
                        <option value="">-请选择-</option>
                        <option value="1">男</option>
                        <option value="0">女</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>省：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="province" name="province"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>市：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="city" name="city"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>区县：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="country" name="country"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>公众号ID：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="mpId" name="mpId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>微信语言：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="language" name="language"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-8">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-9">
                    <div class="btn btn-success radius" onclick="submit()">修改</div>
                </div>
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/js/H-ui.js"></script>
<script type="text/javascript" src="/js/H-ui.min.js"></script>
<script type="text/javascript" src="/js/postJson.js"></script>
<script type="text/javascript" src="/js/root.js"></script>
<script>
    var custId = parent.$("#dataId").attr("custId");
    var pageNum = parent.$("#dataId").attr("pageNum");
    function getData() {
        var url = "/custBaseController/getCustBaseById";
        $.ajax({
            url: url,
            data: {
                "custId": custId
            },
            type: "post",
            async: false,
            dataType: 'json',
            success: function (msg) {
                // console.log(JSON.stringify(msg))
                if (msg.success) {
                    $("#name").val(msg.data.name)
                    $("#certCode").val(msg.data.certCode)
                    $("#mobile").val(msg.data.mobile)
                    $("#openId").val(msg.data.openId)
                    $("#unionId").val(msg.data.unionId)
                    $("#nickname").val(msg.data.nickname)
                    $("#headImgUrl").val(msg.data.headImgUrl)
                    $("#bbId").val(msg.data.bbName)
                    $("#yyId").val(msg.data.yyName)
                    $("#zzId").val(msg.data.zzName)
                    $("#distributionCenterId").val(msg.data.distributionCenterId)
                    $("#vipType").find("option[value='" + msg.data.vipType + "']").attr("selected", true);
                    $("#vipRank").find("option[value='" + msg.data.vipRank + "']").attr("selected", true);
                    $("#sex").find("option[value='" + msg.data.sex + "']").attr("selected", true);
                    $("#province").val(msg.data.province)
                    $("#city").val(msg.data.city)
                    $("#country").val(msg.data.country)
                    $("#mpId").val(msg.data.mpId)
                    $("#language").val(msg.data.language)
                    if(msg.data.thumbImagePath != null) {
                        var img  = "<li class='fl pos_r imgCon'><i class='pos_a iminus' onclick='removeImg(this)'></i><img src='"+msg.data.headImgUrl+"' onclick='imgClick(this)'/></li>"
                        $(".imageAppend").removeClass("hide").find("ul").append(img);
                        $(".addFileLoad").addClass("hide");
                    }
                }
            }
        })
    }
    getData()
    /*提交*/
    var flag = true;
    var fileArr = [];
    function submit() {
        if (!flag) {
            return false;
        }
        flag = false;

        var vipRank = $("#vipRank").find("option:selected").val();
        if(vipRank == null || vipRank == '') {
            parent.layer.msg('会员等级不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        var jsonArry = {
            "vipRank": vipRank,
            "id": custId
        }
        var jsondata = JSON.stringify(jsonArry);
        var url = "/custBaseController/updateCustBase";
        $.ajax({
            type: "post",
            url: url,
            data: jsondata,
            dataType: "json",
            contentType: "application/json",
            async: false,
            success: function (msg) {
                if (msg.success) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.msg("修改成功！", {icon: 1, time: 3000});
                    window.parent.frames.getData(Number(pageNum));
                    parent.layer.close(index);
                } else {
                    parent.layer.msg(msg.errorMessage, {icon: 2, time: 5000});
                    flag = true;
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var XmlStatus = XMLHttpRequest.status
                if (XmlStatus == 401) {
                    alert(XmlError.error401)
                    parent.window.location.href = "login"
                }
                if (XmlStatus == 403) {
                    alert(XmlError.error403)
                }
            }
        })
    }
    function changeFile(formDataArr) {
        var value = $(formDataArr).val();
        if(value == "") {
            return false;
        }
        var val = value.substring(value.lastIndexOf(".") + 1).toLowerCase();
        if(val !== "png" && val !== "jpg" && val !== "jpeg" && val !== "bmp") {
            parent.layer.msg('图片格式不正确，请重新上传！', {icon: 2, time: 3000});
            return false;
        }
        fileArr.push(formDataArr.files[0]);
        forImage(formDataArr);
    }

    function fileClick(obj) {
        $("input[type=file]").click();
    }
    function forImage(data) {
        for(var i = 0; i < data.files.length; i++) {
            var file = new FileReader();
            file.readAsDataURL(data.files[i]);
            file.onload = function() {
                var img  = "<li class='fl pos_r imgCon'><i class='pos_a iminus' onclick='removeImg(this)'></i><img src='"+this.result+"' onclick='imgClick(this)'/></li>"
                $(".imageAppend").removeClass("hide").find("ul").append(img);
                $(".addFileLoad").addClass("hide");
            }
        }
    }
    //点击小图显示大图
    function imgClick(obj) {
        var src = $(obj).prop("src");
        window.open(src);
    }
    //删除图片
    function removeImg(obj) {
        $(".addFileLoad input").val("");
        fileArr = [];
        $(obj).parent().remove();
        $(".imageAppend").addClass("hide");
        $(".addFileLoad").removeClass("hide");
    }
</script>
</body>
</html>